import { ProFormSwitch } from '@ant-design/pro-components';

const CommonFormSwitch: React.FC<any> = ({ required, rules = [], ...props }) => {
  return (
    <ProFormSwitch
      {...props}
      rules={
        rules.some((rule: any) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请设置${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormSwitch.defaultProps = { required: false };

export default CommonFormSwitch;
